-- Used for rendering sprites to the screen and handling their animation


sprite = {}
	sprite.timePerFrame = 0.05;
	sprite.lastTime = 0.0;
	
	sprite.paused = true;
	sprite.loop = true;
	
	sprite.framecount = 4;
	sprite.frame = 0;
	sprite.row = 0;
	
	sprite.w = 0;
	sprite.h = 0;
	
	sprite.filepath = "content/null.png"


function sprite:Init(_w,_h,_framecount,_filepath)
	self.filepath = _filepath
	self.w = _w
	self.h = _h
	self.framecount = _framecount
	self.image = love.graphics.newImage( self.filepath )	
end

function sprite:Update(dt)
	self.lastTime = self.lastTime + dt
	if (self.lastTime > self.timePerFrame) then
		self.frame= self.frame + 1
		self.lastTime = self.lastTime - self.timePerFrame
	end
	
	if (self.framecount < self.frame) then
		self.frame = 0
	end
end

function sprite:Draw(_x, _y)
    qFrame = love.graphics.newQuad( self.w*self.frame, self.h*self.row, 
		self.w, self.h,
		self.image:getWidth(), self.image:getHeight() )
	love.graphics.drawq( self.image, qFrame, _x, _y)
end